<template>
    <div>
        <el-row>
            <el-col :span="17">
                <el-input v-model="url" placeholder="请输入rtsp监控流地址"></el-input>
            </el-col>
            <el-col :span="5">
                <el-button type="primary" @click="getFfmpeg()">获取</el-button>
            </el-col>
        </el-row>
        <div style="border: 1px dashed #3a8ee6;margin-top: 20px;height: 470px;">
            <video style="width:100%; height:100%; object-fit: fill;" ref="playerWin" id="playerWin"></video>
        </div>
    </div>
</template>

<script>
    import flvjs from "flv.js";
    export default {
        name: "onlinePreview",
        data(){
            return {
                //rtsp在线测试地址
                url:'rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov',
                player: null
            }
        },
        methods:{
            getFfmpeg: function () {
                if (flvjs.isSupported()) {
                    let video = document.getElementById('playerWin');
                    if (video) {
                        this.player = flvjs.createPlayer({
                            type: "flv",
                            isLive: true,
                            url: `ws://10.1.1.106:8090/rtsp/3301061000004/10/1/aokToESTP/std.sdp?url=`+this.url
                        });
                        this.player.attachMediaElement(video);
                        try {
                            this.player.load();
                            this.player.play();
                        } catch (error) {
                            console.log(error);
                        }
                    }
                }
            }
        }
    }
</script>

<style scoped>

</style>